package net.thermetics.fx.auth;

import org.springframework.security.core.context.SecurityContext;


/**
 * Bean controlled by Spring to supply the current user information for each request.
 * @author projectmoon
 *
 */
public class UserAuth {
	private final GaeUser principal;
	
	public UserAuth() {
		principal = null;
	}
	
	/**
	 * Receives constructor arg from Spring.
	 * @param facade
	 */
	public UserAuth(SecurityContextHolderFacade facade) {
		SecurityContext ctx = facade.getContext();
		if (ctx.getAuthentication().getPrincipal() instanceof GaeUser) {
			principal = (GaeUser)ctx.getAuthentication().getPrincipal();
		}
		else {
			principal = null;
		}
	}
	
	public GaeUser getPrincipal() {
		return principal;
	}
}
